class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None

def is_huiwen(listnode):
    temp_list = []

    # 只有一个节点默认回文
    if listnode.next is None:
        return True

    # 遍历链表，存除到列表
    curr = listnode
    while curr is not None:
        temp_list.append(curr.val)
        curr = curr.next

    for i in range(len(temp_list) // 2):
        if temp_list[i] != temp_list[len(temp_list) - i - 1]:
            return False
        return True


n1 = ListNode(1)
n2 = ListNode(2)
n3 = ListNode(2)
n4 = ListNode(1)

n1.next = n2
n2.next = n3
n3.next = n4

print(is_huiwen(n1))

m1 = ListNode(1)
m2 = ListNode(2)
m3 = ListNode(3)
m4 = ListNode(4)

m1.next = m2
m2.next = m3
m3.next = m4
print(is_huiwen(m1))

k = ListNode(1)
print(is_huiwen(k))


